-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use X-Forwared-Host for resolving host #13
base: master
Are you sure you want to change the base?
Conversation
X-Forwarded-For is normally used for getting the original client IP, whereas X-Forwarded-Host is normally used to get the original host requested by the client. X-Forwarded-For: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For X-Forwarded-Host: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
Even if that is correct this can be a breaking change for various installations. |
And beside that, this the "for" header works totally fine with reverse proxies like traefik, caddy or haproxy. |
It was actually because of traefik I found this. The latest traefik version sets X-Forwarded-For to an IP address, and X-Forwarded-Host to the original requested hostname. I understand the point about backward compatibility. Maybe if both were supported? |
Maybe it should be better to check for host and as a fallback check the for header. The traefik change have been integrated within the last release? |
I am fairly new to Traefik, but I think they have been using Oxy for a long time (It is the library handling the proxying). And Oxy has been using X-Forwarded-For for client ip for at least 3 years. So this is how traefik has been handling this always. I can't think of a good way to support both headers for the same thing other than configuration. If we handle both, then it has to be either:
or
But since both fields will most likely be filled out in most cases, you would always take the first one in both cases. |
I'm using traefik already quite long and it always worked fine for me in combination with this middleware |
That is quite odd. Have you checked that the X-Forwarded-For header is set? And it is an actual hostname and not an IP? |
There is an pass host Header Option I'm using with traefik |
But that passes the "Host" header, and according to the resolveHost algorithm it will never get to that if the X-Forwarded-For header is set. The algorithm is:
So in your case with traefik you have to somehow suppress the passing of X-Forwarded-For or do something else instead. Have you tried to debug what headers you get from the traefik request? |
I will prepare a docker-compose scenario to see the exact behavior |
Can we instead add a field to the Config struct, such as location.go:
config.go:
cc @hho |
What have to be done to make this PR go forward? |
Use an updated version of gin-contrib/location to get the correct host PR already opened here: gin-contrib/location#13 fix #49
Use an updated version of gin-contrib/location to get the correct host PR already opened here: gin-contrib/location#13 fix #49
I just ran into this with traefik as well and was very confused by what I was seeing. |
WHY THIS IS NOT MERGED? |
I agree, bump the major version and get this released, but for anyone else who is using this module and needs a quick workaround: // location - detects the scheme (http/https) and hostname of the server via the http.Request
locConfig := location.DefaultConfig()
locConfig.Headers.Host = "X-Forwarded-Host" // Workaround BUG in location middleware
router.Use(location.New(locConfig)) |
Agree. Just ran into the same thing with kubernetes ingress-nginx. In my opinion using |
X-Forwarded-For is normally used for getting the original client IP, whereas X-Forwarded-Host is normally used to get the original host requested by the client.
X-Forwarded-For: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
X-Forwarded-Host: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host